package com.demo.http;

import reactor.core.publisher.Mono;
import reactor.netty.DisposableServer;
import reactor.netty.http.server.HttpServer;

public class Server {

	public static void main(String[] args) {
        DisposableServer server = HttpServer.create()
				            		.port(8083)
				            		.route(routes ->
				            			routes
				        				// 当我们发出一个GET请求去访问/hello时就会得到一个字符串Hello World!
				        				.get("/hello", (request, response) -> response.sendString(Mono.just("Hello World!")))
				        				// 当我们发出一个 POST请求去访问 /echo时就会将请求体作为响应内容返回
				                        .post("/echo",(request, response) -> response.send(request.receive().retain()))
				                        // 当我们发出一个 GET请求去访问 /path/{param}，时就会得到一个请求路径参数param的值
				                        .get("/path/{param}", (request, response) -> response.sendString(Mono.just(request.param("param")))))
				            		.bindNow();

        server.onDispose()
              .block();
    }

}
